//初始化导航栏
function initNav(){
	loginUser=getCookie("username");
	console.log(loginUser);
	if(loginUser!=""){
		var navUsername=document.getElementById("curUser").getElementsByTagName("a")[0];
		console.log(navUsername);
		var loginButton=document.getElementById("toLoginPage");
		var regButton=document.getElementById("toRegPage");
		navUsername.firstChild.textContent="欢迎，"+loginUser;
		loginButton.style.display="none";
		regButton.style.display="none";
	}
}

//获得cookie某个字段的值，返回字符串
function getCookie(name){
    var strcookie = document.cookie;//获取cookie字符串
    var arrcookie = strcookie.split(";");//分割
	// console.log("length of cookie:",arrcookie.length);
    for (var i=0; i<arrcookie.length; i++) {
		// console.log(arrcookie[i]);
        var arr = arrcookie[i].split("=");
		arr[0]=arr[0].replace(/^\s*|\s*$/g,"");
        if (arr[0] == name){
            return arr[1];
        }
    }
    return "";
}

//获取当前时间
function getTimeStr(){
	var d=new Date();
	var time=String(d.getFullYear())+"-"+String(d.getMonth()+1)+"-"+String(d.getDate())+" "+String(d.getHours())+":"+String(d.getMinutes())+":"+String(d.getSeconds());
	return time;
}